<?php

use Biz\model\ShopCategoryClassify;
use Biz\service\BrandPreFecture;

/**
 * @deprecated
 */
class TopCategoryListAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_NOTHING;
    const HOT_BRAND = '热门品牌';

    public function main()
    {
        $show = 1;
        $top_categorys = [];
        $list = ShopCategoryClassify::select("*", ['status' => ShopCategoryClassify::STATUS_NORMAL, 'deep' => ShopCategoryClassify::DEEP_FIRST_CLASSIFY, 'ORDER' => ['sort' => 'DESC']]);

        if(file_exists(BrandPreFecture::RECOMMEND_ONOFF_FILE)) {
            $on_off_json = file_get_contents(BrandPreFecture::RECOMMEND_ONOFF_FILE);
            $on_off_arr = json_decode($on_off_json, true);
            if(isset($on_off_arr['prefecture_tab']) && !(int) $on_off_arr['prefecture_tab']) {
                $show = 0;
            }
        }

        if($list && is_array($list) && $show) {
            $top_categorys = (array) array_column($list, 'classify_name');
        }
        $data = array_merge([self::HOT_BRAND], $top_categorys);
        $data = array_values(array_filter($data));
        $this->setSuccess(['list' => $data]);
    }

}